/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-08-14
 * Time: 18:27
 */
public class CirculateMyQueue {
    private int[] arr;
    private int front;
    private int rear;
    private int size;

    //构造方法
    public CirculateMyQueue(int k) {
        this.arr = new int[k];
    }

    //入队列
    public boolean offer(int data) {
        if (isFull()) {
            return false;
        }
        this.arr[this.rear] = data;
        this.rear = (this.rear + 1) % this.arr.length;
        this.size++;
        return true;
    }

    //出队列
    public boolean poll() {
        if (isEmpty()) {
            return false;
        }
        this.front = (this.front + 1) % this.arr.length;
        this.size--;
        return true;
    }

    //获取队首元素
    public int getFront() {
        if (isEmpty()) {
            return -1;
        }
        return this.arr[this.front];
    }

    //获取队尾元素
    public int getRear() {
        if (isEmpty()) {
            return -1;
        }
        int mark = (this.rear == 0?this.arr.length - 1:rear - 1);
        return this.arr[mark];
    }

    //检查循环队列是否为空
    public boolean isEmpty() {
        return this.size == 0;
    }

    //检查队列是否为满
    public boolean isFull() {
        return this.size == this.arr.length;
    }
}
